﻿#ifndef __AVOID_BW_CONTROL_SWUI_TREE_H__
#define __AVOID_BW_CONTROL_SWUI_TREE_H__
#include "ctlList.h"
#include <array>

namespace swui
{
#pragma warning(push)
#pragma warning(disable:4250)
	class ctlTree : virtual public ctlRoot, 
		public IFont, public IBackground
	{
		template<typename, std::size_t> friend class std::array;
	public:
		static const ctlControlType uniqueType = ctlControlType::ctlTree;
	public:
		struct nodeInfo
		{
			static const unsigned nullNode = ~0;

			ctlList* ctrl;
			unsigned parent;
			unsigned prev_sibling;
			unsigned next_sibling;
			unsigned first_child;
			unsigned this_node;
		};
	public:
		virtual ~ctlTree() { destroy(); }
		bool create(ctlRoot* parent, ctlRect rect, 
			const ctlStyleList& style = ctlStyleList(ctlStyleList::common));
	public:
		unsigned getRootNodeIndex();
		nodeInfo getNode(unsigned node);
		unsigned insertChild(unsigned node, unsigned index, const ctlText& text = "");
		bool eraseNode(unsigned node);
		/* 查找当前节点在其兄弟节点中的顺序
		 * 根节点为 0 */
		unsigned findNodeSiblingIndex(unsigned node);
	protected:
		virtual void _redraw_(_ctlInterior::drawInfo*){};
	private:
		class _tree_struct;
		template<typename> class _tree_slot;
	private:
		std::shared_ptr<_tree_struct> _tree_data;
	};
#pragma warning(pop)
}

#endif